package com.fc.test.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.Convert;
import com.fc.test.mapper.auto.ForeJobMapper;
import com.fc.test.model.auto.ForeJob;
import com.fc.test.model.auto.ForeJobExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 *  ForeJobService
 * @Title: ForeJobService.java 
 * @Package com.fc.test.service 
 * @author fuce_自动生成
 * @email 115889198@qq.com
 * @date 2020-04-26 16:58:58  
 **/
@Service
public class ForeJobService implements BaseService<ForeJob, ForeJobExample>{
	@Autowired
	private ForeJobMapper foreJobMapper;
	
      	   	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<ForeJob> list(Tablepar tablepar,String name){
	        ForeJobExample testExample=new ForeJobExample();
	        testExample.setOrderByClause("id ASC");
	        if(name!=null&&!"".equals(name)){
	        	testExample.createCriteria().andUserIdLike("%"+name+"%");
	        }
			if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
	        	testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
	        }
	        PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
	        List<ForeJob> list= foreJobMapper.selectByExample(testExample);
	        PageInfo<ForeJob> pageInfo = new PageInfo<ForeJob>(list);
	        return  pageInfo;
	 }

	@Override
	public int deleteByPrimaryKey(String ids) {
				
			List<String> lista=Convert.toListStrArray(ids);
			ForeJobExample example=new ForeJobExample();
			example.createCriteria().andIdIn(lista);
			return foreJobMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public ForeJob selectByPrimaryKey(String id) {
				
			return foreJobMapper.selectByPrimaryKey(id);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(ForeJob record) {
		return foreJobMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(ForeJob record) {
				
		//添加雪花主键id
		record.setId(SnowflakeIdWorker.getUUID());
			
				
		return foreJobMapper.insertSelective(record);
	}
	
	
	@Override
	public int updateByExampleSelective(ForeJob record, ForeJobExample example) {
		
		return foreJobMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(ForeJob record, ForeJobExample example) {
		
		return foreJobMapper.updateByExample(record, example);
	}

	@Override
	public List<ForeJob> selectByExample(ForeJobExample example) {
		
		return foreJobMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(ForeJobExample example) {
		
		return foreJobMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(ForeJobExample example) {
		
		return foreJobMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param foreJob
	 * @return
	 */
	public int checkNameUnique(ForeJob foreJob){
		ForeJobExample example=new ForeJobExample();
		example.createCriteria().andUserIdEqualTo(foreJob.getUserId());
		List<ForeJob> list=foreJobMapper.selectByExample(example);
		return list.size();
	}


}
